/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       loader.h
 * Author:     karooolek
 * Created on: 2009-03-22
 *
 **********************************************************************************************************************/

#ifndef LOADER_H_
#define LOADER_H_

namespace mGameEngine
{

/**
 * Interface for resource loaders.
 * When loader is created it doesn't start to load resource.
 * load() method must be called to load data.
 * unload() method is implicitly called when destroying loader.
 * Derived loader should define method to get loaded resource.
 * Overriden method load() should update _state field respectivly to
 * loading state.
 */
class Loader
{
protected:
    /**
     * Loading state
     */
    volatile float _state;

public:
    /**
     * Create new loader.
     * Loading state is initially 0.
     */
    Loader();

    /**
     * Destroy loader and free loaded resource.
     */
    virtual ~Loader();

    /**
     * Check if loading has finished
     * @return true if loading has finished, false otherwise
     */
    bool isLoaded() const
    {
        return _state >= 1.0f;
    }

    /**
     * Get loading state.
     * @return actual loading state. 0.0 if loading hasn't started yet
     * up to 1.0 when loading has finished
     */
    float getLoadingState() const
    {
        return _state;
    }

    /**
     * Start loading.
     */
    virtual void load() = 0;

    /**
     * Start unloading.
     */
    virtual void unload() = 0;
};

}

#endif // LOADER_H_
